package com.sq.universe.base.service.impl;

import com.sq.universe.base.dao.BaseDao;
import com.sq.universe.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 抽象类实现基本的业务
 * @author sunqian 2020.05.14
 * @param <T>
 */
public abstract class BaseServiceImpl<T,M extends BaseDao> implements BaseService<T> {

    @Autowired
    protected M baseDao;

    @Override
    @Transactional
    public Integer insert(T entity) {
        return (Integer) this.baseDao.insert(entity);
    }

    @Override
    @Transactional
    public Integer update(T entity) {
        return (Integer) this.baseDao.update(entity);
    }

    @Override
    @Transactional
    public Integer delete(T entity) {
        return (Integer) this.baseDao.delete(entity);
    }

    @Override
    @Transactional
    public Integer logicalDelete(T entity) {
        return (Integer) this.baseDao.logicalDelete(entity);
    }

    @Override
    @Transactional
    public List<T> query(T entity) {
        return this.baseDao.query(entity);
    }

    @Override
    @Transactional
    public T get(T entity) {
        return (T) this.baseDao.get(entity);
    }

    @Override
    @Transactional
    public T getById(Integer id){
        return (T) this.baseDao.getById(id);
    }

    @Override
    @Transactional
    public List<Map> sqlQuery(String sql) {
        return this.baseDao.sqlQuery(sql);
    }

    @Override
    @Transactional
    public void executeSql(String sql) {
        this.baseDao.executeSql(sql);
    }
}
